package com.maxmlr.framework.mybatisplus;

import com.alibaba.druid.pool.DruidDataSource;
import com.maxmlr.framework.test.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * @ClassName tt
 * @Description TODO
 * @Author maxiao
 * @Date 2020/3/19 下午4:34
 * @Version V1.0
 */
public class Demo {
    public static void main(String[] args) throws Exception {

        Class.forName("com.mysql.jdbc.Driver");
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mysql://47.107.172.86:3306/cat?useUnicode=true&characterEncoding=utf8");
        dataSource.setUsername("maxiao");
        dataSource.setPassword("cniavj");

        Connection connection = dataSource.getConnection();

        String sql= "select id,name,age from user ";
        PreparedStatement ps = connection.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        while (rs.next()){
            int id = rs.getInt(1);
            String name = rs.getString(2);
            int age = rs.getInt(3);
            User user = new User(id, name, age);
            int row = rs.getRow();
            Object id1 = rs.getObject("id");
            System.out.println(user+"---"+row+"---"+id1);
        }

        rs.close();
        ps.close();
        connection.close();


    }
}
